import React, { Component } from 'react'
import './index.css'
import PropTypes from 'prop-types'
export default class Footer extends Component {
    static propTypes = {
        checkAllTodo: PropTypes.func.isRequired,
        cleanAllDone: PropTypes.func.isRequired
    }
    //权限checkbox的回调
    handleCheckAll = (event) => {
        this.props.checkAllTodo(event.target.checked)
    }
    //清除所有已完成任务的回调
    handleCleanAllDone = () => {
        this.props.cleanAllDone()
    }
    render() {
        const { todos } = this.props
        //已完成的个数
        const doneCount = todos.reduce((pre, current) => pre + (current.done ? 1 : 0), 0);
        //总数
        const total = todos.length;
        return (
            <div className="todo-footer" >
                <label>
                    <input type="checkbox" checked={doneCount === total && total != 0 ? true : false} onChange={this.handleCheckAll}></input>
                </label>
                <span>
                    <span>已完成{doneCount}</span>/全部{total}
                </span>
                <button onClick={this.handleCleanAllDone} className="btn btn-danger">清除已完成任务</button>
            </div>
        )
    }
}
